package com.uziot.activiti6.controller.editor;

import io.swagger.annotations.Api;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.Model;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @author shidt
 * @version V1.0
 * @className PageController
 * @date 2021-02-26 10:38:41
 * @description
 */

@Api(tags = "编辑器-编辑视图跳转")
@Controller
public class EditorPageDirectController {

    @Autowired
    private RepositoryService repositoryService;

    @GetMapping(value = {"/editor", "/index.html", "index"})
    public String index(@RequestParam(required = false) String modelId) {
        if (StringUtils.isEmpty(modelId)) {
            return "/error";
        }
        Model modelData = repositoryService.getModel(modelId);
        if (modelData != null) {
            return "/modeler";
        }
        return "/error";
    }
}
